package user

import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        method("GET")
        url("/api/users/query") {
            queryParameters {
                optional(parameter("username", "zhang"))
            }
        }
    }
    response {
        status(200)
        body("""
        [
            {
                "id":1,
                "email":"123456@qq.com",
                "mobilePhone":12345678901,
                "userName":"zhang"
            },
            {
                "id":2,
                "email":"12345678@qq.com",
                "mobilePhone":12345678902,
                "userName":"li"
            }
        ]
        """)
        bodyMatchers {
            jsonPath('$[*]', byType())
            jsonPath('$[*].id', byRegex(number()))
            jsonPath('$[*].email', byRegex(email()))
            jsonPath('$[*].mobilePhone', byRegex(number()))
            jsonPath('$[*].userName', byType())
        }
        headers {
            contentType(applicationJson())
        }
    }
}
